{header}
<link rel="stylesheet" type="text/css" href="/static/plugins/webuploader-0.1.5/webuploader.css">
<script type="text/javascript" src="/static/plugins/webuploader-0.1.5/webuploader.min.js"></script>
<div class="card">
  <div class="card-header">
    操作
  </div>
  <div class="card-body">
    <button type="button" class="btn btn-primary" id="save">保存</button>
  </div>
</div>
<form>
  <div class="form-group">
    <label>类型</label>
    <div class="list-group" style="max-height: 300px;overflow-y: auto;">
	  {type_button_html}
    </div>
  </div>
  <div class="form-group">
    <label for="group-number">编号</label>
    <input type="text" class="form-control" id="group-number" aria-describedby="group-number">
  </div>
  <div class="form-group">
    <label>审核员</label>
    <div class="list-group" style="max-height: 300px;overflow-y: auto;">
	  {examine_button_html}
    </div>
  </div>
  <div class="form-group">
    <label>发布员</label>
    <div class="list-group" style="max-height: 300px;overflow-y: auto;">
	  {publish_button_html}
    </div>
  </div>
  <div class="form-group">
    <label>剩余选题</label>
	{movie_name_ul}
  </div>
  <script type="text/javascript">
    var current_examine = 0;
    var current_publish = 0;
    var current_type = '';
    function active_examine(id) {
      $('#examine' + current_examine).removeClass('active');
      current_examine = id;
      $('#examine' + id).addClass('active');
    }
    function active_publish(id) {
      $('#publish' + current_publish).removeClass('active');
      current_publish = id;
      $('#publish' + id).addClass('active');
    }
    function active_type(id) {
      $('#type' + current_type).removeClass('active');
      current_type = id;
      $('#type' + id).addClass('active');
    }
    $(function () {
      $('#save').on('click', function () {
        var group_type = current_type;
        var group_number = $('#group-number').val();
        if (group_type === '') {
          layer.alert('必须选择一个类型', {icon: 0});
          return;
        } else if (group_number === '') {
          layer.alert('表单不能有空', {icon: 0});
          return;
        } else if (group_type.indexOf('\'') !== -1 || group_type.indexOf('"') !== -1 ||
          group_number.indexOf('\'') !== -1 || group_number.indexOf('"') !== -1) {
          layer.alert('表单不能含有引号', {icon: 0});
          return;
        }
        if (current_examine === 0 || current_publish === 0) {
          layer.alert('必须选择一个审核员和发布员', {icon: 0});
          return;
        }
        var save = $('#save');
        save.html('保存中');
        save.attr('disabled', true);
        $.ajax({
          url: '{base_url}library/upload_group',
          type: 'post',
          data: {
            group_type: group_type,
            group_number: group_number,
            examine: current_examine,
            publish: current_publish
          },
          success: function (data) {
            var d = data.split(':');
            save.html('保存');
            save.attr('disabled', false);
            if (d.length !== 2) {
              console.error(data);
              layer.alert('服务器返回非法数据', {icon: 2});
              return;
            }
            if (d[0] === 'fail') {
              layer.alert('提交失败:' + d[1], {icon: 2});
              console.error('提交失败:' + d[1]);
            } else if (d[0] === 'success') {
              location.href = '{base_url}group_list?p=1';
            } else {
              layer.alert('服务器返回多余数据', {icon: 2});
            }
          },
          error: function (data) {
            layer.alert('上传失败', {icon: 2});
            console.error(data.responseText);
          }
        });
      });
    });
  </script>
</form>
{footer}

